package com.centling.smartSealForPhone.activity

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import com.centling.smartSealForPhone.R
import com.centling.smartSealForPhone.bean.LoginBean
import com.centling.smartSealForPhone.constants.SPConstants
import com.centling.smartSealForPhone.constants.UserType
import com.centling.smartSealForPhone.utils.SPUtil
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_feature_demo.*

class FeatureDemoActivity : TitleBarActivity() {


    val loginBean = Gson().fromJson(SPUtil.getString(SPConstants.LOGIN_JSON), LoginBean::class.java)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_feature_demo)

        setTitleBarText("功能演示")

        judgeTypeAndSet()
    }
    private fun judgeTypeAndSet(){
        if (TextUtils.equals("0", loginBean.equipRegisterInfo.equipType)){
            when (SPUtil.getString(SPConstants.USER_TYPE)) {
                UserType.EQUIP_COMMON_USER -> {
                    ll_feature_demo_container.getChildAt(0).visibility = View.VISIBLE
                    ll_feature_demo_container.getChildAt(0).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.EQUIP_COMMON_USER + "_0"))
                    }
                }
                UserType.EQUIP_ADMIN -> {
                    ll_feature_demo_container.getChildAt(0).visibility = View.VISIBLE
                    ll_feature_demo_container.getChildAt(0).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.EQUIP_ADMIN + "_" + 0))
                    }
                }
                UserType.EQUIP_OPERATOR -> {
                    ll_feature_demo_container.getChildAt(0).visibility = View.VISIBLE
                    ll_feature_demo_container.getChildAt(0).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.EQUIP_OPERATOR + "_" + 0))
                    }
                }
                UserType.SERVER_USER -> {
                    ll_feature_demo_container.getChildAt(3).visibility = View.VISIBLE
                    ll_feature_demo_container.getChildAt(3).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.SERVER_USER + "_" + 3))
                    }
                    ll_feature_demo_container.getChildAt(4).visibility = View.VISIBLE
                    ll_feature_demo_container.getChildAt(4).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.SERVER_USER + "_" + 4))
                    }
                }
            }
        } else {
            when (SPUtil.getString(SPConstants.USER_TYPE)) {
                UserType.EQUIP_COMMON_USER ->{
                    ll_feature_demo_container.getChildAt(0).visibility=View.VISIBLE
                    ll_feature_demo_container.getChildAt(0).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "1_" + UserType.EQUIP_COMMON_USER + "_0"))
                    }
                }
                UserType.EQUIP_ADMIN ->{
                    for (i in 0..2){
                        ll_feature_demo_container.getChildAt(i).visibility=View.VISIBLE
                        ll_feature_demo_container.getChildAt(i).setOnClickListener {
                            startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "1_" + UserType.EQUIP_ADMIN + "_" + i))
                        }
                    }
                }
                UserType.EQUIP_OPERATOR ->{
                    for (i in 0..2){
                        ll_feature_demo_container.getChildAt(i).visibility=View.VISIBLE
                        ll_feature_demo_container.getChildAt(i).setOnClickListener {
                            startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "1_" + UserType.EQUIP_OPERATOR + "_" + i))
                        }
                    }
                }
                UserType.SERVER_USER ->{
                    ll_feature_demo_container.getChildAt(3).visibility=View.VISIBLE
                    ll_feature_demo_container.getChildAt(3).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.SERVER_USER + "_" + 3))
                    }
                    ll_feature_demo_container.getChildAt(4).visibility=View.VISIBLE
                    ll_feature_demo_container.getChildAt(4).setOnClickListener {
                        startActivity(Intent(mContext, FeatureDemoDisplayActivity::class.java).putExtra("feature_type", "0_" + UserType.SERVER_USER + "_" + 4))
                    }
                }
            }
        }
    }
}
